package com.zxjbyte.yiyi.module.system.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.zxjbyte.yiyi.framework.common.domain.api.PageResult;
import com.zxjbyte.yiyi.framework.common.util.ValidationUtil;
import com.zxjbyte.yiyi.framework.mybatis.service.impl.BaseServiceXImpl;
import com.zxjbyte.yiyi.framework.mybatis.util.Condition;
import com.zxjbyte.yiyi.module.system.domain.entity.DictItemPO;
import com.zxjbyte.yiyi.module.system.domain.param.dict.DictItemListParam;
import com.zxjbyte.yiyi.module.system.domain.vo.DictItemVO;
import com.zxjbyte.yiyi.module.system.mapper.DictItemMapper;
import com.zxjbyte.yiyi.module.system.service.DictItemService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author zhangxingjia
 * @Date 2024/1/24 16:18
 * @Version: 1.0
 */
@Service
public class DictItemServiceImpl extends BaseServiceXImpl<DictItemMapper, DictItemPO> implements DictItemService {

    @Override
    public PageResult<DictItemVO> list(DictItemListParam param) {
        IPage<?> page = Condition.getPage(param);
        List<DictItemVO> voList = getBaseMapper().listPageDictItems(page, param);
        return PageResult.of(voList, page);
    }

    @Override
    public DictItemVO detail(Long id) {
        DictItemVO vo = getBaseMapper().getDetailById(id);
        ValidationUtil.assertNotNull(vo, () -> "字典项不存在");
        return vo;
    }

    @Override
    public List<DictItemPO> listByDictId(Long dictId) {
        return lambdaQuery().eq(DictItemPO::getDictId, dictId).list();
    }
}
